package CaseDemos;

import java.util.Scanner;

/**
 * 方法的重载可以简单理解为，相同的方法名，在传入不同的参数时调用不同的具体重载的方法。
 */


public class MethodReloadTest {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("请输入两个整数，回车结束：");

        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println("请再输入两个小数，回车结束：");

        double c = sc.nextDouble();
        double d = sc.nextDouble();

        System.out.println(calculateAplusB(a,b)); //int + int
        System.out.println(calculateAplusB(c,d)); //double + double
        System.out.println(calculateAplusB(a,c)); //int + double
        System.out.println(calculateAplusB(c,b)); //double + int

    }

    //方法声明和定义
    public static int calculateAplusB(int a, int b){
        return a + b;
    }
    //方法重载，可以同时识别小数的加法
    public  static double calculateAplusB(double a, double b){
        return a + b;
    }
    public  static double calculateAplusB(int a, double b){
        return (double) a + b;
    }
    public  static double calculateAplusB(double a, int b){
        return a + (double) b;
    }


}
